﻿using Logging.Entities;
using ReadAndWrite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Logging.LogTXT
{
    public class LoggingTXT :ILogService
    {
        public String NameApplication
        {
            get;
            private set;
        }

        public String PathApplication
        {
            get;
            private set;
        }

        public LoggingTXT(String nameApplication, String pathApplication)
        {
            NameApplication = nameApplication;
            PathApplication = pathApplication;
        }

        #region ILogService Membres

        public void WriteLog(Utils.LogTrace log)
        {
            String dateDay = DateTime.Now.ToShortDateString().Replace('/', '_');
            String path = PathApplication + @"\" + NameApplication + @"_" + dateDay + @".txt";

            StreamWriter stream = new StreamWriter(path, true);
            stream.AutoFlush = true;
            stream.WriteLine(String.Format("{0} : {1} : {2} : {3} : {4} : {5}",
                              DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                              log.CreateTrace().UTILISATEUR_CONNECTE,
                              log.CreateTrace().NIVEAU,
                              log.CreateTrace().MACHINE,
                              log.CreateTrace().ECRAN,
                              log.CreateTrace().DETAIL_MESSAGE));

            stream.Close();
        }

        #endregion
    }
}
